const BaseController = require('../BaseController');

/**
 * 
 */
class ApiController extends BaseController {
	// 接口分类查询
	async queryApi() {
        const { ctx, app, service } = this;
        const id = ctx.params.id;
        console.log("======id========", id);
		// 解析参数主要是查询参数
		const res = await service.admin.apiService.queryApi(id);
		return this.ok(res);
	}
	// 创建接口
	async createApi() {
		const { ctx, app, service } = this;
		ctx.validate({
			apiName: { type: 'string', required: true },
			apiPath: { type: 'string', required: true },
			apiType: { type: 'string', required: true },
			categoryId: { type: 'string', required: true }
		});
		const res = await service.admin.apiService.createApi(ctx.request.body);
		return this.ok(res);
	}
	// 更新接口
	async updateApi() {
		const { ctx, app, service } = this;
		ctx.validate({
			categoryName: { type: 'string', required: true },
			parentId: { type: 'string', required: true },
			_id: { type: 'string', required: true }
		});
		const res = await service.admin.apiService.updateApi(ctx.request.body);
		return this.ok(res);
	}
	// 删除接口
	async deleteApi() {
		const { ctx, app, service } = this;
		// 解析参数主要是查询参数
		const id = ctx.params.id;
		ctx.validate({
			id: { type: 'string', required: true }
		}, { id });
		const res = await service.admin.apiService.deleteApi(id);
		return this.ok(res);
	}
}

module.exports = ApiController;
